<template>
  <div class="wt-tab">
    <div class="tab">
      <ul :class="type">
        <li v-for="(item, index) in dataSource" :key="index" :class="{active:active == index}" @click="handle(item, index)">
          {{ item.title }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import formMixins from '@/mixins/formMixins'

export default {
  name: 'BaseTab',
  // 注册资源
  components: {
    mixins: [formMixins]
  },
  props: {
    dataSource: { // 数据来源
      type: Array,
      default: () => {
        return []
      }
    },
    currIndex: { // 当前处于第几个选项
      type: Number | String,
      default: () => {
        return 0
      }
    },
    type: { // 组件类型，（可选）（可选值："default", "full")
      type: String,
      default: () => {
        return 'default'
      }
    }
  },
  // 定义数据
  data() {
    return {
      active: '' // 当前处于第几个选项
    }
  },
  computed: {
  },
  created() {
    this.active = this._props.currIndex // 获取父组件的参数值
  },
  mounted() {
  },
  // 定义方法或事件
  methods: {
    handle(item, index) {
      this.active = index // 设置当前选项
      this.$emit('handle', item, index) // 传值父组件
    }
  }
}
</script>
<style lang='scss' scoped>
.wt-tab {
     width: 100%;
     .tab {
         background: #fff;
        //  border-bottom: 1px solid #ebebeb;
         &::after {
              transform: scaleY(.5);
              height: 1px;
              content: '';
              border-bottom: 1px solid #ccc;
              display: block;
          }
         ul {
             display: flex;
             font-size: 0.7rem;
             &.default {
                 justify-content: space-around;
             }
             &.full {
                 justify-content: space-between;
                 li {
                     flex: 1;
                     text-align: center;
                 }
             }
             li {
                 height: 2rem;
                 line-height: 2rem;
                &.active {
                    border-bottom: 2px solid #1BB5F1;
                    margin-bottom: -1px;
                    color: #1BB5F1;
                }
             }
         }
     }
 }
</style>
